import { toSuccess, useEntityManager } from "@sker/core"
import { KsLiveRoomLog } from "@sker/entities"
import { useData } from "@sker/runtime"
import dayjs from "dayjs"
import { z } from "zod"


export default async () => {
    const input = z.object({
        uuid: z.string(),
        pkg: z.string()
    })
    const startDate = dayjs().startOf('day').toDate()
    const endDate = dayjs().endOf('day').toDate()
    const body = input.parse(useData())
    return await useEntityManager(async m => {
        const list = await m.createQueryBuilder()
            .select('log.count', 'count')
            .addSelect('log.update_date', 'update_date')
            .addSelect('log.status', 'status')
            .from(KsLiveRoomLog, 'log')
            .where('create_date>:start and create_date<:end', { start: startDate, end: endDate })
            .andWhere('uuid=:uuid', { uuid: body.uuid })
            .andWhere('pkg=:pkg', { pkg: body.pkg })
            .execute()
        return toSuccess(list)
    })
}

